import { View } from "../../../mvc/core/View";
import { GTextFormat } from "../../../common/GTextFormat";
import { FontUtil } from "../../../common/font/FontUtil";
import { LayerManager } from "../../manager/LayerManager";
import { LoaderManager } from "../../../../com/gengine/resource/LoaderManager";
import { FilterConst } from "../../../component/gconst/FilterConst";
import { ClockManager } from "../../manager/ClockManager";
import { SecTimer } from "../../../../com/gengine/core/frame/SecTimer";
import { TimerType } from "../../../../com/gengine/core/frame/TimerType";
import { Language } from "../../../../extend/language/Language";
import { ImageInfo } from "../../../../com/gengine/resource/info/ImageInfo";
import { SWFInfo } from "../../../../com/gengine/resource/info/SWFInfo";
import { Cache } from "../../cache/Cache";
import { ObjCreate } from "../common/ObjCreate";
import { HTMLUtil } from "../../../../com/gengine/utils/HTMLUtil";
import { FrameTimer } from "../../../../com/gengine/core/frame/FrameTimer";
import { RemainTimeTool } from "../award/RemainTimeTool";
import { BossConfig } from "../../resource/BossConfig";
import { CutCounts } from "./CutCounts";
import { SceneRange } from "../../scene/map/SceneRange";
import { GLabel } from "../../../../com/mui/controls/GLabel";
type int = number;
//class CopyCountDownLabel
    
    export  class CopyCountDownLabel extends View
    {
        constructor()
        {
            super();
            this._yellowTfSmall = new GTextFormat(FontUtil.songtiName, 12, 16776960, null, null, null, null, null, flash.text.TextFormatAlign.CENTER);
            this._yellowTfBig = new GTextFormat(FontUtil.songtiName, 14, 16776960, null, null, null, null, null, flash.text.TextFormatAlign.CENTER);
            this._bosses = [];
            this.layer = LayerManager.uiLayer;
            this.mouseChildren = false;
            this.mouseEnabled = false;
            this.createChildren();
            return;
        }

        public /* override */ hide(): void
        {
            if (this._timer) 
            {
                this._timer.stop();
                this._timer.dispose();
                this._timer = null;
            }
            if (this._frame) 
            {
                if (this._frame.running) 
                {
                    this._frame.stop();
                }
                this._frame = null;
            }
            super.hide();
            return;
        }

        public /* override */ show(arg1: int=0, arg2: int=0): void
        {
            super.show(arg1, arg2);
            if (this.parent) 
            {
                this.parent.setChildIndex(this, 0);
            }
            if (this._ringLabelBottle) 
            {
                this.addChildAt(this._ringLabelBottle, 1);
            }
            return;
        }

        public setTimeLabel_Ring(arg1: int=-1, arg2: int=-1, arg3: string="环数"): void
        {
            var loc1=0;
            this._timerType = arg3;
            if (!this._ringLabelBg) 
            {
                LoaderManager.instance.load("copy_countdownRing_bg2.png", this.onRingBgLoaded);
                LoaderManager.instance.load("copy_countdownRing_bottle.swf", this.onRingBottleLoaded);
            }
            this._timeLabel.setStyle("textFormat", this._yellowTfSmall);
            this._timeLabel.textField.filters = [FilterConst.glowFilter];
            if (this._timerType != CopyCountDownLabel.RING) 
            {
                if (this._timerType == CopyCountDownLabel.BOSS_REFRESH) 
                {
                    this._bosses.push({"bossId": arg1, "refreshTime": ClockManager.instance.nowDate.time + arg2 * 1000});
                    loc1 = Math.round((this._bosses[0]["refreshTime"] - ClockManager.instance.nowDate.time) / 1000);
                    this._timerNumSec = loc1;
                }
            }
            else 
            {
                if (this._ring != -1) 
                {
                    this._ring = arg1;
                }
                this.setLabelRing();
            }
            if (this._timerType != CopyCountDownLabel.RING) 
            {
                if (!this._timer) 
                {
                    this._timer = new SecTimer();
                    this._timer.addListener(TimerType.ENTERFRAME, this.onTimerHandler);
                }
                this._timer.start();
            }
            return;
        }

        /* internal  */setLabelRing(): void
        {
            var loc1=Math.floor((this._ring + 4) / 5);
            this._timeLabel.text = Language.getStringByParam(60092, loc1);
            if (this._ring != 1) 
            {
                if (this._ring == 300) 
                {
                    this._timeLabel.text = Language.getString(60094);
                }
            }
            else 
            {
                this._timeLabel.text = Language.getString(60093);
            }
            return;
        }

        /* internal  */onRingBgLoaded(arg1: ImageInfo): void
        {
            if (!this._ringLabelBg) 
            {
                this._ringLabelBg = new Object /* flash.display.Bitmap */(arg1.bitmapData);
                this.addChildAt(this._ringLabelBg, 0);
                this.stageResize();
            }
            return;
        }

        /* internal  */onRingBottleLoaded(arg1: SWFInfo): void
        {
            if (!this._ringLabelBottle && arg1 && arg1.clip) 
            {
                this._ringLabelBottle = arg1.clip;
                this._ringLabelBottle.mouseChildren = false;
                this._ringLabelBottle.mouseEnabled = false;
                this.addChildAt(this._ringLabelBottle, 1);
                this.stageResize();
                this.updateRingBottleExp();
            }
            return;
        }

        public updateRingBottleExp(): void
        {
            var loc1=NaN;
            var loc2=0;
            if (Cache.instance.copy.defendCopyExp - this._lastExp >= 10000) 
            {
                this._addExpEach = 1111;
            }
            else if (Cache.instance.copy.defendCopyExp - this._lastExp >= 5000) 
            {
                this._addExpEach = 111;
            }
            else 
            {
                this._addExpEach = 11;
            }
            if (!this._expLabel) 
            {
                this._expLabel = ObjCreate.createLabel("", 0, 0, 200, 30, flash.text.TextFormatAlign.CENTER, this, true, 16776960);
                this._expLabel.toolTipData = HTMLUtil.addColor(Language.getString(60095), "#FFFFFF");
            }
            if (!this._frame) 
            {
                this._frame = new FrameTimer();
                this._frame.addListener(TimerType.ENTERFRAME, this.onEnterFrameHandler);
            }
            if (!this._frame.running) 
            {
                this._frame.start();
            }
            if (this._ringLabelBottle) 
            {
                if (Cache.instance.copy.copyInfo && Cache.instance.copy.copyInfo.code == 124) 
                {
                    loc1 = Cache.instance.copy.defendCopyExp / Cache.instance.copy.defendMaxExpSingle;
                }
                else if (Cache.instance.copy.copyInfo && Cache.instance.copy.copyInfo.code == 125) 
                {
                    loc1 = Cache.instance.copy.defendCopyExp / Cache.instance.copy.defendMaxExpGroup;
                }
                loc1 = loc1 > 1 ? 1 : loc1;
                loc2 = Math.round(this._ringLabelBottle.totalFrames * loc1);
                this._ringLabelBottle.gotoAndStop(loc2);
            }
            return;
        }

        /* internal  */onEnterFrameHandler(arg1: FrameTimer): void
        {
            var loc1=Cache.instance.copy.defendCopyExp;
            this._lastExp = this._lastExp + this._addExpEach;
            if (this._lastExp > loc1) 
            {
                this._lastExp = loc1;
            }
            this._expLabel.setStyle("textFormat", this._yellowTfBig);
            this._expLabel.text = Language.getString(60096) + this._lastExp;
            if (this._lastExp >= loc1) 
            {
                if (this._frame && this._frame.running) 
                {
                    this._frame.stop();
                }
            }
            return;
        }

        public setTimeLabel_End(arg1: int=-1): void
        {
            this._timerType = CopyCountDownLabel.REMAIN_TIME;
            this._timeLabel.setStyle("textFormat", this._yellowTf);
            this._timeLabel.textField.filters = [];
            if (arg1 != -1) 
            {
                this._timerNumSec = arg1;
            }
            if (!this._timer) 
            {
                this._timer = new SecTimer();
                this._timer.addListener(TimerType.ENTERFRAME, this.onTimerHandler);
            }
            this._timer.start();
            return;
        }

        /* internal  */setLabelEnd(): void
        {
            this._timeLabel.text = Language.getString(60097) + RemainTimeTool.getRemainTimeBySeconds(this._timerNumSec);
            return;
        }

        public setBossRefreshLabel(): void
        {
            var loc1=0;
            var loc2=null;
            if (this._bosses.length > 0) 
            {
                loc1 = Math.round((this._bosses[0]["refreshTime"] - ClockManager.instance.nowDate.time) / 1000);
                if (loc1 <= 0) 
                {
                    this._bosses.pop();
                    if (this._bosses.length > 0) 
                    {
                        this._timerNumSec = Math.round((this._bosses[0]["refreshTime"] - ClockManager.instance.nowDate.time) / 1000);
                    }
                }
                if (this._bosses.length > 0) 
                {
                    loc2 = BossConfig.instance.getInfoByCode(this._bosses[0]["bossId"] as int);
                    this._timeLabel.text = Language.getStringByParam(60098, loc2.boss.name, RemainTimeTool.getRemainTimeBySeconds(this._timerNumSec));
                }
                else 
                {
                    this._timeLabel.text = Language.getString(60099);
                }
            }
            else 
            {
                this._timeLabel.text = Language.getString(60100);
            }
            return;
        }

        public setKillCountsLabel(arg1: int, arg2: int, arg3: int): void
        {
            if (!this._killCountsLabel) 
            {
                this._killCountsLabel = new CutCounts();
                this._killCountsLabel.mouseEnabled = false;
                this._killCountsLabel.mouseChildren = false;
                this.addChild(this._killCountsLabel);
                this.stageResize();
            }
            if (arg1 != 0) 
            {
                this._killCountsLabel.setCutsNum(arg1, arg2);
            }
            this._scoreLabel.text = Language.getString(60101) + arg3;
            return;
        }

        /* internal  */onTimerHandler(arg1: SecTimer): void
        {
            if (this._timerType != CopyCountDownLabel.REMAIN_TIME) 
            {
                if (this._timerType == CopyCountDownLabel.BOSS_REFRESH) 
                {
                    this.setBossRefreshLabel();
                }
            }
            else 
            {
                this.setLabelEnd();
            }
            --this._timerNumSec;
            if (this._timerNumSec < 0 && this._bosses.length == 0) 
            {
                this._timer.stop();
            }
            else if (this._timerNumSec <= 29 && this._timerType == CopyCountDownLabel.REMAIN_TIME) 
            {
                this._timeLabel.setStyle("textFormat", this._redTf);
            }
            return;
        }

        public stageResize(): void
        {
            if (this._ringLabelBg) 
            {
                this._ringLabelBg.x = SceneRange.display.width - 240 - 35 + 40;
                this._ringLabelBg.y = 170 + 40;
            }
            if (this._ringLabelBottle) 
            {
                this._ringLabelBottle.x = SceneRange.display.width - 240 - 75 - 136 - 10;
                this._ringLabelBottle.y = 53;
            }
            if (this._timeLabel && (this._timerType == CopyCountDownLabel.RING || this._timerType == CopyCountDownLabel.BOSS_REFRESH)) 
            {
                this._timeLabel.x = SceneRange.display.width - 230;
                this._timeLabel.y = 220;
            }
            else if (this._timeLabel && this._timerType == CopyCountDownLabel.REMAIN_TIME) 
            {
                this._timeLabel.x = SceneRange.display.width - 500;
                this._timeLabel.y = 120;
            }
            if (this._expLabel) 
            {
                this._expLabel.x = SceneRange.display.width - 230;
                this._expLabel.y = 245;
            }
            if (this._scoreLabel) 
            {
                this._scoreLabel.x = SceneRange.display.width - 500;
                this._scoreLabel.y = 155;
            }
            if (this._killCountsLabel) 
            {
                this._killCountsLabel.x = 400;
                this._killCountsLabel.y = 120;
            }
            return;
        }

        public stopTimer(): void
        {
            if (this._timer && this._timer.running) 
            {
                this._timer.stop();
            }
            return;
        }

        /* internal  */createChildren(): void
        {
            this._yellowTf = new GTextFormat();
            this._yellowTf.color = 16776960;
            this._yellowTf.align = flash.text.TextFormatAlign.LEFT;
            this._yellowTf.size = 20;
            this._yellowTf.bold = true;
            this._redTf = new GTextFormat();
            this._redTf.color = 16711680;
            this._redTf.align = flash.text.TextFormatAlign.LEFT;
            this._redTf.size = 20;
            this._redTf.bold = true;
            this._greenTf = new GTextFormat();
            this._greenTf.color = 65280;
            this._greenTf.align = flash.text.TextFormatAlign.LEFT;
            this._greenTf.size = 20;
            this._greenTf.bold = true;
            this._timeLabel = ObjCreate.createLabel("", 0, 0, 200, 30, flash.text.TextFormatAlign.LEFT, this);
            this._timeLabel.mouseEnabled = false;
            this._timeLabel.mouseChildren = false;
            this._scoreLabel = ObjCreate.createLabel("", 0, 35, 200, 30, flash.text.TextFormatAlign.LEFT, this);
            this._scoreLabel.setStyle("textFormat", this._greenTf);
            this._scoreLabel.mouseEnabled = false;
            this._scoreLabel.mouseChildren = false;
            this.stageResize();
            return;
        }

        public static /* const */RING: string="环数";

        public static /* const */REMAIN_TIME: string="剩余时间";

        public static /* const */BOSS_REFRESH: string="boss刷新";

        /* internal */ /* var */_yellowTf: Object /* flash.text.TextFormat */;

        /* internal */ /* var */_yellowTfSmall: Object /* flash.text.TextFormat */;

        /* internal */ /* var */_yellowTfBig: Object /* flash.text.TextFormat */;

        /* internal */ /* var */_redTf: Object /* flash.text.TextFormat */;

        /* internal */ /* var */_greenTf: Object /* flash.text.TextFormat */;

        /* internal */ /* var */_ringLabelBg: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_ringLabelBottle: Object /* flash.display.MovieClip */;

        /* internal */ /* var */_timeLabel: GLabel;

        /* internal */ /* var */_scoreLabel: GLabel;

        /* internal */ /* var */_expLabel: GLabel;

        /* internal */ /* var */_killCountsLabel: CutCounts;

        /* internal */ /* var */_timer: SecTimer;

        /* internal */ /* var */_timerNumSec: int;

        /* internal */ /* var */_timerType: string;

        /* internal */ /* var */_frame: FrameTimer;

        /* internal */ /* var */_ring: int;

        /* internal */ /* var */_bosses: Array<any>;

        /* internal */ /* var */_lastExp: int;

        /* internal */ /* var */_addExpEach: int=11;

        /* internal */ /* var */_nextKillTime: int;
    }
